import { createApp } from "vue";
import "./style.css";
import App from "./App.vue";
// 引入axios
import axios from "axios";
import VueAxios from "vue-axios";
// 引入vue-router
import { createMemoryHistory, createRouter } from "vue-router";
// 引入pinia
import { createPinia,defineStore } from "pinia";
const pinia = createPinia();
// 引入element-plus
import ElementPlus from "element-plus";
import "element-plus/dist/index.css";
import * as ElementPlusIconsVue from "@element-plus/icons-vue"; //引入element-plus图标

// 引入路由组件
import HomePage from "./components/HomePage.vue";
import list from "./components/list.vue";
import AboutView from "./components/AboutView.vue";

// import cors from "cors";// 跨域

const routes = [
  { path: "/", component: HomePage },
  { path: "/list", component: list },
  { path: "/about", component: AboutView },
];

const router = createRouter({
  history: createMemoryHistory(),
  routes,
});

export const useCounterStore = defineStore("counter", {
  state: () => {
    return { count: 0 };
  },
  // 也可以这样定义
  // state: () => ({ count: 0 })
  actions: {
    increment() {
      this.count++;
    },
  },
});

const app = createApp(App);

app.use(VueAxios, axios); // 全局注册axios
app.use(router); // 全局注册router
app.use(ElementPlus); // 全局注册element-plus
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component);
}// 全局注册element-plus图标
app.provide("$axios", app.config.globalProperties.axios); // 挂载axios到全局
// app.use(cors())
app.use(pinia);// 挂载pinia

app.mount("#app");

export const count = defineStore("count", {
  state: () => ({ count: 0 }),
  actions: {
    increment() {
      this.count++;
    },
  },
  getters:{}
});